package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理")
public class WmChannelController {

    @Autowired
    private IWmChannelService channelService;

    @PostMapping(value = "/list",name = "根据名称分页查询频道列表")
    @ApiOperation(value = "listByName",notes = "根据名称分页查询频道列表")
    @ApiImplicitParam(name="dto",dataType = "ChannelDto" ,required=true)
    public ResponseResult listByName(@RequestBody ChannelDto dto){
       return channelService.listByName(dto);
    }


    @PostMapping(name = "保存频道")
    @ApiOperation(value = "saveChannel",notes = "保存频道")
    @ApiImplicitParam(name="wmChannel",dataType = "WmChannel" ,required=true)
    public ResponseResult saveChannel(@RequestBody WmChannel wmChannel){
        return channelService.saveChannel(wmChannel);
    }


    @GetMapping(value = "channels",name = "所有频道列表")
    @ApiOperation(value = "channels",notes = "保存频道")
    public ResponseResult channels(){
        List<WmChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }


}
